package com.app.lxx.pregnancyberth.widge;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.app.lxx.pregnancyberth.R;


public class CustomerSortView extends FrameLayout {
    private String strTitle;
    private Drawable drawable;
    private int color;
    private View mView;
    private TextView custom_tv;
    private ImageView custom_iv;
    private View custom_line;

    public CustomerSortView(Context context) {
        super(context );
    }

    public CustomerSortView(Context context, AttributeSet attrs) {
        super(context, attrs );
        initView(context);
        initAttrs(context, attrs);
        setData();
    }

    public CustomerSortView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
        initAttrs(context, attrs);
        setData();
    }

    private void initAttrs(Context context, AttributeSet attrs) {
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CustomerSortView);
        strTitle = typedArray.getString(R.styleable.CustomerSortView_title);
        drawable = typedArray.getDrawable(R.styleable.CustomerSortView_drawable_left);
        color = typedArray.getColor(R.styleable.CustomerSortView_drawable_bottom, getResources().getColor(R.color.transparent));
        typedArray.recycle();
    }

    private void initView(Context context) {
        mView = LayoutInflater.from(context).inflate(R.layout.view_cutomer_sort, null);
        custom_tv = mView.findViewById(R.id.custom_tv);
        custom_tv.setTextSize(14);//zjq 修改字体大小
        custom_iv = mView.findViewById(R.id.custom_iv);
        custom_line = mView.findViewById(R.id.custom_line);
        this.addView(mView);
    }

    private void setData() {
        if (!TextUtils.isEmpty(strTitle)) {
            custom_tv.setText(strTitle);
            custom_iv.setImageDrawable(drawable);
        }
        custom_line.setBackgroundColor(color);
    }

    public void setColor(int color) {
        custom_line.setBackgroundColor(getResources().getColor(color));
    }
}
